/**
 * 1. 类 calse
 * */

class Animal {
  x
  constructor(x) {
    this.x = x;
  }
  sayHi() {
    return 'shan' + this.x;
  }
}
var cat = new Animal('jack');

/**
 * 2. 类 的继承
 * */

class dog extends Animal {
  constructor(x) {
    super(x);
    console.log(x);
  }
  sayHi() {
    return super.sayHi() + 'is my'
  }
}

let c = new dog('see');
console.log(c.sayHi());

/**
 * 3. 类 的存取器  get set
 * */

class Animals {
  name
  constructor(name) {
    this.name = name;
  }
  get() {
    return 'Jack'
  }

  set(value) {
    console.log('setter' + value);
  }
}

let n = new Animals('kitty');
n.name = 'shanshan'; //setter shanshan
console.log(n.name); // jack

/**
 * 3. TypeScript 可以使用三种访问修饰符 public、private  protected
 * */

class PersonName {
  public six
  private name
  protected age
  public constructor(name, six, age) {
    this.name = name;
    this.six = six;
    this.age = age;
  }
}

let lili = new PersonName('lyly', '女', 22);
// lili.name // 报错 被私有化。无法访问
// lili.age // 报错受保护， 只能在 子类中访问；

/**
 * 4. 抽象类 abstract 用于定义抽象类和其中的抽象方法。
 * */
abstract class Cat {
  public name;
  public constructor(name) {
    this.name = name;
  }
  public abstract sayHi();
}

// let a = new Cat('Jack') // 报错 抽象类 不能实例化

/**
 * 5. 类的类型 type
 * */

class WebP {
  name: string
  constructor(name: string, age: number) {
    this.name = name;
  }
  sayHi(): string {
    return `${this.name} + is your`
  }
}

let o = new WebP('oo', 10);
console.log(o.name);